home *** CD-ROM | disk | FTP | other *** search
/ GameStar 2004 April / Gamestar_61_2004-04_dvdb.iso / DVDStar / Editace / hltp.exe / {app} / Applications / QuArK / plugins / maptexpos.py < prev    next >
Text File  |  2004-01-05  |  5KB  |  196 lines

  1.  
  2. ########################################################
  3. #
  4. #               Alternate Texture Position Plugin
  5. #
  6. #
  7. #                  by tiglari@hexenworld.com
  8. #     
  9. #
  10. #   You may freely distribute modified & extended versions of
  11. #   this plugin as long as you give due credit to tiglari &
  12. #   Armin Rigo. (It's free software, just like Quark itself.)
  13. #
  14. #   Please notify bugs & possible improvements to
  15. #   tiglari@hexenworld.com
  16. #  
  17. #
  18. ##########################################################
  19.  
  20. #$Header: /cvsroot/quark/runtime/plugins/maptexpos.py,v 1.6 2003/12/18 21:51:46 peter-b Exp $
  21.  
  22.  
  23. Info = {
  24.    "plug-in":       "Alternate Texture Positioning",
  25.    "desc":          "Alternate Texture Positioning",
  26.    "date":          "Nov 4, 1999",
  27.    "author":        "tiglari",
  28.    "author e-mail": "tiglari@hexenworld.com",
  29.    "quark":         "Version 5.11" }
  30.  
  31. import quarkx
  32. import quarkpy.mapmenus
  33. import quarkpy.mapentities
  34. import quarkpy.qmenu
  35. import quarkpy.mapeditor
  36. import quarkpy.qbaseeditor
  37. import quarkpy.mapcommands
  38. import quarkpy.mapoptions
  39. import quarkpy.qhandles
  40. import quarkpy.mapbtns
  41. import quarkpy.dlgclasses
  42. from quarkpy.maputils import *
  43.  
  44.  
  45. class TexPosDlg (quarkpy.dlgclasses.LiveEditDlg):
  46.     #
  47.     # dialog layout
  48.     #
  49.  
  50.     endcolor = AQUA
  51.     size = (180,200)
  52.     dfsep = 0.35
  53.  
  54.     dlgdef = """
  55.         {
  56.             Style = "9"
  57.         Caption = "Texture Positioning Dialog"
  58.  
  59.         scale: = 
  60.         {
  61.         Txt = "Scale"
  62.         Typ = "EQ"
  63.         Hint = "x, y scales; map units per texture tile" $0D "  y is the direction along the edge away from the closest corner," $0D "  x is the direction along the other edge at that corner, away from it"
  64.         }
  65.  
  66.         sep: = {Typ="S" Txt=" "} 
  67.  
  68.         offset: =
  69.         {
  70.         Txt = "Offset"
  71.         Typ = "EQ"
  72.         Hint = "x, y offsets; floats map units" $0D "  y is the direction along the edge away from the closest corner," $0D "  x is the direction along the other edge at that corner, away from it"
  73.         }
  74.  
  75.         sep: = {Typ="S" Txt=" "} 
  76.  
  77.         tilt: = {
  78.         Txt = "Tilt"
  79.         Typ = "EU"
  80.         Hint = "`tilt' angle, in degrees."
  81.         }
  82.         
  83.         sep: = {Typ="S" Txt=" "} 
  84.  
  85.         shear: = {
  86.         Txt = "Shear"
  87.         Typ = "EU"
  88.         Hint = "`shear' angle, in degrees." $0D "  (angle between texture y-axis and perp to texture x-axis)"
  89.         }
  90.         
  91.       
  92.         sep: = { Typ="S" Txt=""}
  93.  
  94.         exit:py = {Txt="" }
  95.     }
  96.     """
  97.  
  98. def read2vec(vals):
  99.   strings = vals.split()
  100.   return eval(strings[0]), eval(strings[1])
  101.  
  102. def PosTexClick(m):
  103.   editor = mapeditor()
  104.   if editor is None: return
  105.   
  106.   class pack:
  107.     "just a place to stick stuff"
  108.   
  109.   pack.o = m.o
  110.   
  111.   def setup(self, pack=pack):
  112.     src = self.src
  113.     face = pack.o
  114.     p0, p1, p2 = face.threepoints(2)
  115.     tp1, tp2 = p1-p0, p2-p0
  116.     scalex, scaley = abs(p1-p0), abs(p2-p0)
  117.     n = face.normal
  118.     vc = face.origin
  119.     v1, v2 = bestaxes(n, self.editor.layout.views[0])
  120. #      squawk("v1: %s, v2: %s"%(v1, v2))
  121.     anglex, angley = (math.atan2(v2*tp1, v1*tp1), math.atan2(v2*tp2, v1*tp2))
  122.     self.src["offset"] = "%.1f %.1f"%(-v1*(vc-p0), -v2*(vc-p0))
  123.     anglex, angley = anglex/deg2rad, angley/deg2rad
  124.     self.src["scale"] = "%.1f %.1f"%(scalex, scaley)
  125.  
  126.     tilt = anglex
  127.     shear = anglex + 90 - angley
  128.  
  129.     self.src["tilt"] = "%.1f"%degcycle(tilt)
  130.     self.src["shear"] = "%.1f"%degcycle(shear)
  131.     
  132.     
  133.   def action(self, pack=pack, editor=editor):
  134.     face = pack.o
  135.     offsetx, offsety = read2vec(self.src["offset"])
  136.     scalex, scaley = read2vec(self.src["scale"])
  137.     tilt = eval(self.src["tilt"])
  138.     shear = eval(self.src["shear"])
  139.  
  140.     anglex = tilt
  141.     angley = anglex + 90 - shear
  142.  
  143.     anglex, angley = anglex*deg2rad, angley*deg2rad
  144.  
  145.     f2 = face.copy()
  146.     vc = face.origin
  147.     n = face.normal
  148.     v1, v2 = bestaxes(n, self.editor.layout.views[0])
  149. #      squawk("1: %s, 2: %s"%(`v1`, `v2`))
  150.     p0 = vc + offsetx*v1 + offsety*v2
  151.     p1 = p0 + (v1*math.cos(anglex) + v2*math.sin(anglex))*scalex
  152.     p2 = p0 + (v1*math.cos(angley) + v2*math.sin(angley))*scaley
  153. #      squawk("0: %s, 1: %s, 2: %s"%(`p0`, `p1-p0`, `p2-p0`))
  154.     f2.setthreepoints((p0, p1, p2), 2)
  155.  
  156.     undo_exchange(editor, face, f2, "position texture")
  157.     pack.o = f2
  158.  
  159.  
  160.     
  161.   TexPosDlg(quarkx.clickform, 'texpos', editor, setup, action)
  162.     
  163.  
  164. def texmenu(o, editor, oldmenu = quarkpy.mapentities.FaceType.menu.im_func):
  165.   "the new right-mouse for sides"
  166.   menu = oldmenu(o, editor)
  167.   texpop = findlabelled(menu, 'texpop')
  168.   texitem = qmenu.item("Position Texture",PosTexClick)
  169.   texitem.o = o
  170.   texpop.items[1:1] = [texitem]
  171.   return menu
  172.   
  173. quarkpy.mapentities.FaceType.menu = texmenu
  174.  
  175. # ----------- REVISION HISTORY ------------
  176. #
  177. #
  178. # $Log: maptexpos.py,v $
  179. # Revision 1.6  2003/12/18 21:51:46  peter-b
  180. # Removed reliance on external string library from Python scripts (second try ;-)
  181. #
  182. # Revision 1.5  2001/06/17 21:10:56  tiglari
  183. # fix button captions
  184. #
  185. # Revision 1.4  2001/06/16 03:19:47  tiglari
  186. # add Txt="" to separators that need it
  187. #
  188. # Revision 1.3  2000/07/24 09:18:11  tiglari
  189. # Put texture-position dialog into a submenu labelled 'texpop', for texture menu cleanup as suggested by Brian Audette
  190. #
  191. # Revision 1.2  2000/06/03 10:25:30  alexander
  192. # added cvs headers
  193. #
  194. #
  195. #
  196. #